Skip to content

✨ Add CT_WRAP #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 10, 2025
Merged

✨ Add CT_WRAP #243

merged 4 commits into from
Jul 10, 2025

Conversation

elbeno
Copy link
Contributor

@elbeno elbeno commented Jul 3, 2025

Problem:

  • It is useful to have a macro that wraps a potentially-constexpr-usable value in stdx::ct when possible, to preserve its constexpr properties.

Solution:

  • Add CT_WRAP that does this.

Notes:

@elbeno elbeno force-pushed the cx-utils branch 6 times, most recently from 87cd5ae to 97c4bd9 Compare July 9, 2025 00:20
@elbeno elbeno marked this pull request as draft July 9, 2025 12:56
@elbeno elbeno force-pushed the cx-utils branch 2 times, most recently from 9dae98b to 2f97d92 Compare July 9, 2025 17:32
@elbeno elbeno marked this pull request as ready for review July 9, 2025 17:39
elbeno added 4 commits July 9, 2025 19:56
Problem:
- It is useful to have a macro that wraps a potentially-`constexpr`-usable value
  in `stdx::ct` when possible, to preserve its `constexpr` properties.

Solution:
- Add `CT_WRAP` that does this.

Notes:
- See intel/compile-time-init-build#743 for some parts
  of this in CIB; this part probably belongs in stdx.
Problem:
- It's useful to have `map`/`transform` in the preprocessor.

Solution:
- Add `pp_map.hpp`.
Problem:
- We want to not forget to apply `CX_VALUE` to arguments in macros when they are
  usable at compile time.

Solution:
- Add `CX_WRAP` which wrap its argument in a `CX_VALUE` when it's possible to
  do so.
Problem:
- It's easy to call `stdx::ct_format` but forget to preserve the constexpr
  nature of the arguments. Especially with literals, e.g.
  `stdx::ct_format<"{}">(42)` results in a runtime format argument.

Solution:
- Add `STDX_CT_FORMAT` which automatically wraps the arguments so that their
  constexpr nature is preserved where possible. `STDX_CT_FORMAT("{}", 42)` is
  now a compile-time formatting operation.
Copy link
Contributor

@mjcaisse-intel mjcaisse-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Looks great. Can't wait to use this!

@bdeane-intel bdeane-intel merged commit 3641035 into intel:main Jul 10, 2025
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants